﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<QualificationLevel>>" %>
<%@ Import Namespace="ViewRes" %>
<script type="text/javascript">

    var loadStudentsLink;

    function loadGroups(levelsSelectId, groupsSelectId) {
        var selectedValue = $("#" + levelsSelectId + " option:selected").val();
        if (selectedValue == "")
            return false;
        selectedValue = '<%:Url.RouteUrl("Default", new {controller = "StudentsGroups", action = "LevelJSON"})%>' + '/' + selectedValue;
        $.getJSON(selectedValue, function(data) {
            $("#" + groupsSelectId).empty();
            $("#" + groupsSelectId).append("<option class='disabled'><%:AdministratorsStrings.ChooseGroup%></option>");
            $(data).each(function() {
                $("#" + groupsSelectId).append("<option value='" + this.id + "'>" + this.name + "</option>");
            });
        });
    }

    function loadStudentsList() {
        var id = $("#GroupsSelect option:selected").val();
        loadStudentsLink = '<%:Url.RouteUrl("Default", new {controller = "Students", action = "Group"})%>' + '/' + id;
        $("#divStudentsList").load(loadStudentsLink);
    }

    function editStudent(link) {
        openDialog(link, '<%:AdministratorsStrings.EditStudent%>', function() {
            $("#divDialog form").attr("onSuccess", "loadActiveEntries();");
        });

    }

    function studentDeleted() {
        loadActiveEntries();
    }

    function loadActiveEntries() {
        $("#divStudentsList").load(loadStudentsLink);
    }
</script>
<div style="margin: 1em auto; position: relative; text-align: left;">
    <div>
        <span class="largeText">
            <%:AdministratorsStrings.QualificationLevel%>
        </span>
        <select id="LevelsSelect" onchange="loadGroups(this.id,'GroupsSelect')">
            <option>
                <%:AdministratorsStrings.ChooseLevel%></option>
            <%
                foreach (QualificationLevel level in Model)
                {%>
            <option value="<%=level.QualificationLevelId%>">
                <%=level.ToString()%></option>
            <%
                }%>
        </select>
    </div>
    <br />
    <div>
        <span class="largeText">
            <%:AdministratorsStrings.Group%>: </span>
        <select id="GroupsSelect" onchange="loadStudentsList()">
        </select>
    </div>
    <br />
    <div id="divStudentsList">
    </div>
</div>
